﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace SendMyZip.DataAcess
{
    public class Settings
    {
        XElement _xElement;
        IEnumerable<XElement> _settings;
        public Settings()
        {
            var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            this._xElement = XElement.Load(assemblyPath + @"\Data\Settings.xml");

            this._settings = this._xElement.Elements();
        }

        public string GetEmail()
        {
            return GetValue("Email");
        }

        public string GetPassword()
        {
            return GetValue("Password");
        }

        public string GetHost()
        {
            return GetValue("Host");
        }

        public string GetPort()
        {
            return GetValue("Port");
        }

        private string GetValue(string key)
        {
            var strValue = string.Empty;

            var element = this._settings.FirstOrDefault(e => e.Attribute("key").Value == key);
            if (element != null)
            {
                strValue = element.Attribute("value").Value;
            }

            return strValue;
        }
    }
}
